#include <iostream>
using namespace std;

const int MOD = 1e9 + 7;

int concatenatedBinary(int n) 
{
    long long res = 0;
    int bitLen = 0;

    for (int i = 1; i <= n; ++i) 
    {
        if ((i & (i - 1)) == 0) 
        {
            bitLen++;
        }
        res = ((res << bitLen) | i) % MOD;
    }

    return (res);
}
